<template>
	<view class="tab">
		<view v-for="(item,index) in list" :key="index" class="tab-item" @click="switchTab(item, index)">
			<image class="tab_img" :src="selectedIndex == index ? item.selectedIconPath : item.iconPath" />
			<view class="tab_text" :style="{color: selectedIndex == index ? selectedColor : color}">{{item.text}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			selectedIndex: { // 当前选中的tab index
				default: 0
			},
		},
		data() {
			return {
				color: "#8a8a8a",
				selectedColor: "#3570f9",
				list: [],
				currentIndex: 0,
			}
		},
		created() {
			this.currentIndex = this.selectedIndex;
			if (uni.getStorageSync('userWindow') == '001') {
				this.list = [{
						"pagePath": "pages/business/home",
						"iconPath": require("../static/icon/hosp.png"),
						"selectedIconPath": require("../static/icon/hosp_active.png"),
						"text": "首页"
					},
					{
						"pagePath": "pages/doctor/doctor",
						"iconPath": require("../static/icon/doctor.png"),
						"selectedIconPath": require("../static/icon/doctor_active.png"),
						"text": "名医"
					},
					{
						"pagePath": "pages/companion/companion",
						"iconPath": require("../static/icon/heart.png"),
						"selectedIconPath": require("../static/icon/heart_active.png"),
						"text": "陪护"
					},
					{
						"pagePath": "pages/mine/mine",
						"iconPath": require("../static/icon/my.png"),
						"selectedIconPath": require("../static/icon/my_active.png"),
						"text": "我的"
					}
				]
			} else {
				this.list = [{
						"pagePath": "pages/business/home",
						"iconPath": require("../static/icon/hosp.png"),
						"selectedIconPath": require("../static/icon/hosp_active.png"),
						"text": "首页"
					},
					{
						"pagePath": "pages/notice/notice",
						"iconPath": require("../static/icon/notice.png"),
						"selectedIconPath": require("../static/icon/notice_active.png"),
						"text": "通知"
					},
					{
						"pagePath": "pages/mine/mine",
						"iconPath": require("../static/icon/my.png"),
						"selectedIconPath": require("../static/icon/my_active.png"),
						"text": "我的"
					}
				]
			}
		},
		methods: {
			switchTab(item, index) {
				this.currentIndex = index;
				let url = item.pagePath;
				uni.switchTab({
					url: '/' + url
				})
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 100rpx;
		background: white;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部

		.tab-item {
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			.tab_img {
				width: 45rpx;
				height: 45rpx;
			}

			.tab_text {
				font-size: 25rpx;
				// margin: 9rpx 0;
			}
		}
	}
</style>